package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

public class HJ37_寻找密码 {
  public static void main(String[] args) throws FileNotFoundException {
    Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/37.txt"));
    String[] sArray = in.nextLine().split(" ");
    String res = "";
    Set<String> set = new TreeSet<>(Comparator.reverseOrder());
    for (String s : sArray) {
      set.add(s);
    }
    for (String s : set) {
      if (check(s, set)) {
        System.out.println(s);
        return;
      }
    }
  }

  static boolean check(String s, Set<String> set) {
    for (int i = 1; i < s.length(); i++) {
      if (!set.contains(s.substring(0, i))) {
        return false;
      }
    }
    return true;
  }
}
